<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-perTemplateSpecRelation-add">
			<div class="form-group">
				<input type="hidden" id="templateId" name="templateId" th:value="${templateId}">
				<input type="hidden" id="specId" name="specId" >
				<label class="col-sm-3 control-label">考核项名称：</label>
				<div class="col-sm-8">
					<select name="status" required class="form-control" id="spec" th:onchange="change(this)" th:with="type=${@templateSpec.selectPerTemplateSpecListByType()}">
						<option value=""></option>
						<option th:each="tepmlate : ${type}" th:text="${tepmlate.specName}" th:value="${tepmlate.specId}" th:attr="specContent=${tepmlate.specContent}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">考核项内容：</label>
				<div class="col-sm-8">
					<textarea id="specContent" name="specContent" rows="16" class="col-sm-5  form-control" type="text" ></textarea>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">权重(%)：</label>
				<div class="col-sm-8">
					<input id="weight" name="weight" class="form-control" type="text" required>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "performance/perTemplateSpecRelation"
		$("#form-perTemplateSpecRelation-add").validate({
			onkeyup: false,
			rules:{
				xxxx:{
					required:true
				},
				weight:{
					number:true,
					range:[1,100]
				}

			},
			focusCleanup: true
		});
		
		function submitHandler() {
			$.post( prefix + "/checkIsLegal",
					{"templateId":  $("#templateId").val(),
					"specId":$.common.trim($("#specId").val())
					},
					function(data){
						if(data=='1'){
							$.modal.alertError("该模板此绩效已经存在，请重新选择绩效考核项！");

						}else{
							if ($.validate.form()) {
								$.operate.save(prefix + "/add", $('#form-perTemplateSpecRelation-add').serialize());
							}
						}
					}
			);

	    }
	    function change(select){
			$('#specContent').text($('#spec option:selected').attr("specContent"));
			$('#specId').val($('#spec option:selected').val());
			$.validate.clear();
		}
	</script>
</body>
</html>
